import {Component, OnInit} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';
import {PersonalDataPage} from '../personalData/personalData'


import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import {CityPickerService} from "./modifyData.service";
import {services} from "../../providers/service";

@Component({
    selector: 'page-modifyData',
    templateUrl: 'modifyData.html',
    providers: [CityPickerService]
})
export class ModifyDataPage implements OnInit {
    personalDetail;
    cityData: any[]; //城市数据
    cityName: string = '广东省 深圳市 南山区'; //初始化城市名
    code: string; //城市编码
    constructor(public navCtrl: NavController,
                public cityPickerSev: CityPickerService,
                public service: services,
                public navParams: NavParams) {

        this.setCityPickerData();
    }

    ngOnInit() {
        this.personalDetail = this.service.personalDetail;
    }

    /**
     * 获取城市数据
     */
    setCityPickerData() {
        this.cityPickerSev.getCitiesData()
            .then(data => {
                this.cityData = data;
            });
    }

    /**
     * 城市选择器被改变时触发的事件
     * @param event
     */
    cityChange(event) {
        console.log(event);
        this.code = event['region'].value
    }

    goback() {
        this.navCtrl.pop(PersonalDataPage);
    }

    save() {
        this.navCtrl.pop(PersonalDataPage);
    }

}
